# -*- coding: utf-8 -*-
#pyhook
import pythoncom
import PyHook3 as pyHook
import time
import os
from ctypes import *
idle=0 
def onMouseEvent(event):
    global idle
    idle=0
    print("MessageName:", event.MessageName)
    return True
 
def onKeyboardEvent(event):
    global idle
    print("Key:", event.Key)
    idle=0
    return True
def scrnsave():
    # filename=r"start C:\Windows\System32\Bubbles.scr"
    # os.system(filename)
    user32 = windll.LoadLibrary('user32.dll')
    user32.LockWorkStation()

def main():
    global idle
    # 创建一个“钩子”管理对象
    hm = pyHook.HookManager()
 
    # 监听所有键盘事件
    hm.KeyDown = onKeyboardEvent
    # 设置键盘“钩子”
    hm.HookKeyboard()
 
    # 监听所有鼠标事件
    hm.MouseAll = onMouseEvent
    # 设置鼠标“钩子”
    hm.HookMouse()
    while True:
        idle+=1
        print(idle)
        if idle>20:
            scrnsave()
            break
        time.sleep(1)
        pythoncom.PumpWaitingMessages()
 
if __name__ == "__main__":
    main()